package net.hangar5.xmlrpc; /* Stub.java The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is "Hangar5 XMLRPC Library". The Initial Developer of the Original Code is James D. Rudnicki. Portions created by James D. Rudnicki are Copyright (C) 2001. All Rights Reserved. Contributor(s): */ import java.net.*; import java.util.Vector; import java.io.*; /** * Stub is a base class for client side stubs. * * It supports both standard procedures that have no namespace and * "object" methods that belong to the specified URI. * * @see StubSensor for an example of how to subclass this. */ public class Stub { /** Client to use */ protected RpcClient client; /** Relative URI of object */ protected String strObjectUri; /** All stubs have a vector of method arguments */ protected Vector vArgs; /** * Global namespace constructor. * The procedure will be at the root URI ( / ). */ public Stub( RpcClient c ) { client = c; strObjectUri = null; vArgs = null; } /** * Object namespace constructor. * The procedure will be at the URI specified. * The URI should be passed with no leading or trailing * "/"'s. */ public Stub( RpcClient c, String strUri ) { client = c; strObjectUri = null; if( strUri != null ) { setObjectUrl( strUri ); } vArgs = null; } /** * Execute the remote call. */ protected Object doCall(String strName) throws RpcException, IOException { Object oRet = null; oRet = client.execute( strObjectUri, strName, vArgs ); return oRet; } /** * Change the URI of this stub. * Can use null to revert to base URI. * Fixup of URI will be performed for leading & trailing /'s * as needed. */ public void setObjectUrl( String strNewUrl ) { /* enforce absolute URL's */ if( strNewUrl.startsWith( "/" ) ) { strObjectUri = strNewUrl; } else { strObjectUri = "/" + strNewUrl; } if( strObjectUri.endsWith( "/" ) ) { strObjectUri = strObjectUri.substring( 0, strObjectUri.length()-2 ); } return; } } // end of Stub